<template>
  <el-dialog
    :title="!dataForm.houseId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="楼盘id" prop="properties Id">
      <el-input v-model="dataForm.properties Id" placeholder="楼盘id"></el-input>
    </el-form-item>
    <el-form-item label="详细地址" prop="houseAddress">
      <el-input v-model="dataForm.houseAddress" placeholder="详细地址"></el-input>
    </el-form-item>
    <el-form-item label="价格" prop="housePrice">
      <el-input v-model="dataForm.housePrice" placeholder="价格"></el-input>
    </el-form-item>
    <el-form-item label="排序" prop="houseSort">
      <el-input v-model="dataForm.houseSort" placeholder="排序"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="houseDate">
      <el-input v-model="dataForm.houseDate" placeholder="更新时间"></el-input>
    </el-form-item>
    <el-form-item label="房屋状态（0为已出售，1为未出售）" prop="houseStatus">
      <el-input v-model="dataForm.houseStatus" placeholder="房屋状态（0为已出售，1为未出售）"></el-input>
    </el-form-item>
    <el-form-item label="经纪人id" prop="houseAgent">
      <el-input v-model="dataForm.houseAgent" placeholder="经纪人id"></el-input>
    </el-form-item>
    <el-form-item label="房屋平米" prop="houseSquaremetre">
      <el-input v-model="dataForm.houseSquaremetre" placeholder="房屋平米"></el-input>
    </el-form-item>
    <el-form-item label="房屋描述" prop="houseDescription">
      <el-input v-model="dataForm.houseDescription" placeholder="房屋描述"></el-input>
    </el-form-item>
    <el-form-item label="房屋类型（0新房，1二手房）" prop="houseSecondhand">
      <el-input v-model="dataForm.houseSecondhand" placeholder="房屋类型（0新房，1二手房）"></el-input>
    </el-form-item>
    <el-form-item label="房屋锁" prop="houseLocking">
      <el-input v-model="dataForm.houseLocking" placeholder="房屋锁"></el-input>
    </el-form-item>
    <el-form-item label="房屋朝向" prop="houseOrientation">
      <el-input v-model="dataForm.houseOrientation" placeholder="房屋朝向"></el-input>
    </el-form-item>
    <el-form-item label="房屋装修" prop="houseRenovation">
      <el-input v-model="dataForm.houseRenovation" placeholder="房屋装修"></el-input>
    </el-form-item>
    <el-form-item label="房屋楼层" prop="houseFloor">
      <el-input v-model="dataForm.houseFloor" placeholder="房屋楼层"></el-input>
    </el-form-item>
    <el-form-item label="房屋类型" prop="houseType">
      <el-input v-model="dataForm.houseType" placeholder="房屋类型"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="houseUpdatetime">
      <el-input v-model="dataForm.houseUpdatetime" placeholder="更新时间"></el-input>
    </el-form-item>
    <el-form-item label="发布时间" prop="houseCreatetime">
      <el-input v-model="dataForm.houseCreatetime" placeholder="发布时间"></el-input>
    </el-form-item>
    <el-form-item label="逻辑删除（1删除，0展示）" prop="houseDelete">
      <el-input v-model="dataForm.houseDelete" placeholder="逻辑删除（1删除，0展示）"></el-input>
    </el-form-item>
    <el-form-item label="用户id" prop="userId">
      <el-input v-model="dataForm.userId" placeholder="用户id"></el-input>
    </el-form-item>
    <el-form-item label="核心卖点" prop="coreSellingPoints">
      <el-input v-model="dataForm.coreSellingPoints" placeholder="核心卖点"></el-input>
    </el-form-item>
    <el-form-item label="业主心态" prop="ownerMentality">
      <el-input v-model="dataForm.ownerMentality" placeholder="业主心态"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          houseId: 0,
          properties Id: '',
          houseAddress: '',
          housePrice: '',
          houseSort: '',
          houseDate: '',
          houseStatus: '',
          houseAgent: '',
          houseSquaremetre: '',
          houseDescription: '',
          houseSecondhand: '',
          houseLocking: '',
          houseOrientation: '',
          houseRenovation: '',
          houseFloor: '',
          houseType: '',
          houseUpdatetime: '',
          houseCreatetime: '',
          houseDelete: '',
          userId: '',
          coreSellingPoints: '',
          ownerMentality: ''
        },
        dataRule: {
          properties Id: [
            { required: true, message: '楼盘id不能为空', trigger: 'blur' }
          ],
          houseAddress: [
            { required: true, message: '详细地址不能为空', trigger: 'blur' }
          ],
          housePrice: [
            { required: true, message: '价格不能为空', trigger: 'blur' }
          ],
          houseSort: [
            { required: true, message: '排序不能为空', trigger: 'blur' }
          ],
          houseDate: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ],
          houseStatus: [
            { required: true, message: '房屋状态（0为已出售，1为未出售）不能为空', trigger: 'blur' }
          ],
          houseAgent: [
            { required: true, message: '经纪人id不能为空', trigger: 'blur' }
          ],
          houseSquaremetre: [
            { required: true, message: '房屋平米不能为空', trigger: 'blur' }
          ],
          houseDescription: [
            { required: true, message: '房屋描述不能为空', trigger: 'blur' }
          ],
          houseSecondhand: [
            { required: true, message: '房屋类型（0新房，1二手房）不能为空', trigger: 'blur' }
          ],
          houseLocking: [
            { required: true, message: '房屋锁不能为空', trigger: 'blur' }
          ],
          houseOrientation: [
            { required: true, message: '房屋朝向不能为空', trigger: 'blur' }
          ],
          houseRenovation: [
            { required: true, message: '房屋装修不能为空', trigger: 'blur' }
          ],
          houseFloor: [
            { required: true, message: '房屋楼层不能为空', trigger: 'blur' }
          ],
          houseType: [
            { required: true, message: '房屋类型不能为空', trigger: 'blur' }
          ],
          houseUpdatetime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ],
          houseCreatetime: [
            { required: true, message: '发布时间不能为空', trigger: 'blur' }
          ],
          houseDelete: [
            { required: true, message: '逻辑删除（1删除，0展示）不能为空', trigger: 'blur' }
          ],
          userId: [
            { required: true, message: '用户id不能为空', trigger: 'blur' }
          ],
          coreSellingPoints: [
            { required: true, message: '核心卖点不能为空', trigger: 'blur' }
          ],
          ownerMentality: [
            { required: true, message: '业主心态不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.houseId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.houseId) {
            this.$http({
              url: this.$http.adornUrl(`/house/salehome/info/${this.dataForm.houseId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.properties Id = data.saleHome.properties Id
                this.dataForm.houseAddress = data.saleHome.houseAddress
                this.dataForm.housePrice = data.saleHome.housePrice
                this.dataForm.houseSort = data.saleHome.houseSort
                this.dataForm.houseDate = data.saleHome.houseDate
                this.dataForm.houseStatus = data.saleHome.houseStatus
                this.dataForm.houseAgent = data.saleHome.houseAgent
                this.dataForm.houseSquaremetre = data.saleHome.houseSquaremetre
                this.dataForm.houseDescription = data.saleHome.houseDescription
                this.dataForm.houseSecondhand = data.saleHome.houseSecondhand
                this.dataForm.houseLocking = data.saleHome.houseLocking
                this.dataForm.houseOrientation = data.saleHome.houseOrientation
                this.dataForm.houseRenovation = data.saleHome.houseRenovation
                this.dataForm.houseFloor = data.saleHome.houseFloor
                this.dataForm.houseType = data.saleHome.houseType
                this.dataForm.houseUpdatetime = data.saleHome.houseUpdatetime
                this.dataForm.houseCreatetime = data.saleHome.houseCreatetime
                this.dataForm.houseDelete = data.saleHome.houseDelete
                this.dataForm.userId = data.saleHome.userId
                this.dataForm.coreSellingPoints = data.saleHome.coreSellingPoints
                this.dataForm.ownerMentality = data.saleHome.ownerMentality
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/house/salehome/${!this.dataForm.houseId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'houseId': this.dataForm.houseId || undefined,
                'properties Id': this.dataForm.properties Id,
                'houseAddress': this.dataForm.houseAddress,
                'housePrice': this.dataForm.housePrice,
                'houseSort': this.dataForm.houseSort,
                'houseDate': this.dataForm.houseDate,
                'houseStatus': this.dataForm.houseStatus,
                'houseAgent': this.dataForm.houseAgent,
                'houseSquaremetre': this.dataForm.houseSquaremetre,
                'houseDescription': this.dataForm.houseDescription,
                'houseSecondhand': this.dataForm.houseSecondhand,
                'houseLocking': this.dataForm.houseLocking,
                'houseOrientation': this.dataForm.houseOrientation,
                'houseRenovation': this.dataForm.houseRenovation,
                'houseFloor': this.dataForm.houseFloor,
                'houseType': this.dataForm.houseType,
                'houseUpdatetime': this.dataForm.houseUpdatetime,
                'houseCreatetime': this.dataForm.houseCreatetime,
                'houseDelete': this.dataForm.houseDelete,
                'userId': this.dataForm.userId,
                'coreSellingPoints': this.dataForm.coreSellingPoints,
                'ownerMentality': this.dataForm.ownerMentality
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
